package com.mifengs.mall.widget;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.AttributeSet;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.mifengs.commonbase.util.LogUtil;
import com.mifengs.commonbase.util.PreferenceUtils;


/**
 * Created by lihaoqi on 2017/11/24.
 */

public class VerifyCodeView extends WebView {


    private Context mContext;

    public VerifyCodeView(Context context) {
        super(context);
        init(context);
    }

    public VerifyCodeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public VerifyCodeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;
        setWebViewClient(new FundWebViewClient());
    }



    private class FundWebViewClient extends WebViewClient {

        private SharedPreferences sharedPreferences;

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            CookieManager cookieManager = CookieManager.getInstance();
            String cookieStr = cookieManager.getCookie(url);
            LogUtil.i("cookie",cookieStr);
            PreferenceUtils.saveCookies(mContext,cookieStr);
        }
    }


}
